package org.hackystat.devcathlon.ui.page.matches.browse;

import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.hackystat.devcathlon.ui.DevcathlonSession;
import org.hackystat.devcathlon.ui.page.DevcathlonBasePage;
import org.hackystat.devcathlon.ui.page.matches.MatchDetailPanel;
import org.hackystat.devcathlon.ui.page.matches.MatchesSession;
import org.hackystat.devcathlon.ui.page.matches.browse.matchpanel.CompletedMatchPanel;
import org.hackystat.devcathlon.ui.page.matches.browse.matchpanel.MatchBrowsePanel;
import org.hackystat.devcathlon.ui.page.matches.browse.matchpanel.PendingMatchPanel;

/**
 * Implements the Browse submenu page.
 * 
 * @author John Zhou
 * 
 */
public class BrowsePage extends DevcathlonBasePage {
  /** Support serialization. */
  private static final long serialVersionUID = 1L;

  private MatchesSession session = DevcathlonSession.get().getMatchesSession();
  
  /**
   * Creates the Browse submenu page. This page and its subpages contain information about matches.
   */
  public BrowsePage() {
    add(new WebMarkupContainer("body") {
      private static final long serialVersionUID = 1L;

      @Override
      public boolean isTransparentResolver() {
        return true;
      }

      @Override
      protected void onComponentTag(ComponentTag tag) {
        tag.put("class", "section-3");
      }
    });
    
    add(new MatchBrowsePanel("matchBrowsePanel", DevcathlonSession.get().getMatchesSession()
          .getMatchNames()));
    try {
      if (session.getUserMatches().isEmpty()) {
        add(new MatchDetailPanel("MatchDetailPanel", null));
      }
      else {
        add(new MatchDetailPanel("MatchDetailPanel", session.getUserMatches().get(0).getName()));
      }
    }
    catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    session.getUserMatches();
    add(new PendingMatchPanel("pendingMatchPanel", DevcathlonSession.get().getMatchesSession()
        .getMatchNames()));
    add(new CompletedMatchPanel("completedMatchPanel", DevcathlonSession.get().getMatchesSession()
          .getMatchNames()));
    
    // Make the tab corresponding to this page bold.
    get("BrowseLink").add(new SimpleAttributeModifier("class", "selected"));
  }
}
